import 'package:flutter/material.dart';

/// 实现页面的动画切换
/// 1. 两个页面显示相同的照片
/// 2. 在两个页面添加Hero

const String IMG_URL =
    'http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fpic.58pic.com%2F58pic%2F13%2F80%2F78%2F35V58PICrWD_1024.jpg&thumburl=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2569486047%2C3428433554%26fm%3D26%26gp%3D0.jpg';

class AnimatingScreenApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final String appTitle = 'Animating Screen Demo';
    return MaterialApp(
      title: appTitle,
      theme: ThemeData(primarySwatch: Colors.red),
      home: AnimatingScreenAppPage(title: appTitle),
    );
  }
}

class AnimatingScreenAppPage extends StatefulWidget {
  final String title;

  AnimatingScreenAppPage({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() => AnimatingScreenAppPageState();
}

class AnimatingScreenAppPageState extends State<AnimatingScreenAppPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: GestureDetector(
        onTap: () {
          Navigator.push(context, MaterialPageRoute(builder: (_) {
            return DetailScreen();
          }));
        },
        child: Image.network(IMG_URL),
      ),
    );
  }
}

class DetailScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GestureDetector(
        onTap: () {
          Navigator.pop(context);
        },
        child: Center(
          child: Image.network(IMG_URL),
        ),
      ),
    );
  }
}
